﻿using Config;
using gfLibrary;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace IYAKASAPortal.PrintAll
{
    public partial class Audit : System.Web.UI.Page
    {
        
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Page.IsPostBack == false)
            {
                btnSearch_Click(sender, e);
            }
        }

        protected void btnSearchAll_Click(object sender, EventArgs e)
        {
            txtKeywords.Text = "";
            btnSearch_Click(sender, e);
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            string strKeywords = txtKeywords.Text;
            string strSql = "select ID,HPHM,JCLSH,VIN,HPZL,GXRQ,JYLB from RESULT_VEHICLE_INFO where IsAudit=0";
            if (strKeywords.Length > 0)
            {
                strSql += "  and ( ";
                strSql += " HPHM like '%" + strKeywords + "%'";
                strSql += " or VIN like '%" + strKeywords + "%'";
                strSql += " or JCLSH like '%" + strKeywords + "%')";
            }
            strSql += " order by ID desc";
            DataTable m_dtTable = new DataTable();
            GreatPager1.BindDataTablePage(ref m_dtTable, AppConfig.g_strConnectionStringSqlClient, strSql, 20);
            rptList.DataSource = m_dtTable;
            rptList.DataBind();
            m_dtTable.Dispose();
        }

        protected void btnPrintAJ_Click(object sender, EventArgs e)
        {
            string strUniqueKey = Request.Form["txtUniqueKey"];

            if ((strUniqueKey == null) || (strUniqueKey.Length == 0) || (gfValidate.Is_Integer(strUniqueKey) == false))
            {
                gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "请选择一条记录！");
                return;
            }

            Response.Redirect("PrintAJ.aspx?UniqueKey=" + strUniqueKey);
        }

        protected void btnSH_Click(object sender, EventArgs e)
        {
            string strUniqueKey = Request.Form["txtUniqueKey"];

            if ((strUniqueKey == null) || (strUniqueKey.Length == 0) || (gfValidate.Is_Integer(strUniqueKey) == false))
            {
                gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "请选择一条记录！");
                return;
            }
            SqlConnection conn = new SqlConnection(AppConfig.g_strConnectionStringSqlClient);
            string strSQL = "update RESULT_VEHICLE_INFO set IsAudit=1 where ID=" + strUniqueKey + "";
            SqlCommand cmd = new SqlCommand(strSQL,conn);
            conn.Open();
            cmd.ExecuteNonQuery();
            conn.Close();
            gfLibrary.gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "审核成功！");
            
            
        }

        protected void GreatPager1_PageIndexChanging(object sender, gfPage.PagerEventArgs e)
        {
            GreatPager1.PageIndex = e.NewPageIndex;

            DataTable m_dtTable = GreatPager1.BindDataTablePage();
            rptList.DataSource = m_dtTable;
            rptList.DataBind();
        }
    }
}